package com.by.controller;

import cn.hutool.core.lang.Dict;
import com.by.bean.Dictionary;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.common.group.V;
import com.by.service.DictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Fsw
 * @com.by.controller
 * @date 2025-02-21 16:33
 */
@RestController
@Api(tags = "字典管理")
@RequestMapping("/api/dictionary")
public class DictionaryController extends BaseController {

    @Autowired
    DictionaryService dictionaryService;


    @ApiOperation("保存字典")
    @PostMapping("/save")
    public ResultBean save(@Validated @RequestBody Dictionary dictionary, BindingResult result) {
        V.validate(result);
        int rs =dictionaryService.save(dictionary);
        return saveResult(rs);

    }
    @ApiOperation("修改字典")
    @PutMapping("/save")
    public ResultBean update(@Validated @RequestBody Dictionary dictionary, BindingResult result) {
        V.validate(result);
        int rs = dictionaryService.update(dictionary);
        return saveResult(rs);

    }


    @ApiOperation("根据pid查询字典")
    @GetMapping("/query/queryByPid/{pid}")
    public ResultBean<List<Dict>> query(@PathVariable("pid") int pid){

        List list =dictionaryService.query(pid);
        return success("字典列表",list);


    }

    }

